import Vue from 'vue'
import Vuex from 'vuex'

import {getRequest} from "@/utils/api";

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        baseImgUrl: '',
        userId: null,
    },
    actions: {
        getBaseImgUrl(context) {
            getRequest('/p/store').then((resp) => {
                context.commit('GetBaseImgUrl', resp.message)
            })
        },
        getUserId(context) {
            getRequest('/cms/user/info', window.sessionStorage.getItem('username')).then((resp) => {
                context.commit('GetUserId', resp.data.id)
            })
        },
    },
    mutations: {
        GetBaseImgUrl(state, baseImgUrl) {
            state.baseImgUrl = baseImgUrl
        },
        GetUserId(state, userId) {
            state.userId = userId
        }
    }
})